# encoding: UTF-8
$LOAD_PATH.unshift File.dirname(__FILE__)
require 'User'

class Student < User
  attr_accessor :marks, :school_class, :school

  def initialize(login, password, name, surname, school_class)
    super(login, password, name, surname)
    @marks = []
    @school_class = school_class
  end;
  
  def average_for(discipline)
    mark_count = 0
    mark_sum = 0
    disciplineRegex = Regexp.new discipline
    marks.each do |mark|
      if mark.discipline =~ disciplineRegex
        mark_count += 1
        mark_sum += mark.evaluation
      end
    end
    if mark_count == 0
      nil
    else
      (mark_sum*1.0) / mark_count
    end
  end

  def add_mark(mark)
    @marks << mark
  end
end